//
//  MineView.m
//  LoveBeeProject
//
//  Created by dix on 2017/1/5.
//  Copyright © 2017年 斯芬克斯. All rights reserved.
//

#import "MineView.h"
#import <Masonry.h>
#import "NSAttributedString+Additon.h"
@interface MineView ()
@end
@implementation MineView

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupUI];
    
    
}

-(NSMutableArray *)arrM
{
    if (_arrM == nil) {
        _arrM = [NSMutableArray new];
    }
    return _arrM;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    UIButton *MyOrder = [self makeTopButtonWithTitle:@"我的订单" andButtonImageName:@"v2_my_order_icon" buttonType:MyOrderBtnType];
    UIButton *MyCoupon = [self makeTopButtonWithTitle:@"优惠券" andButtonImageName:@"v2_my_coupon_icon" buttonType:MyCouponBtnType];
    UIButton *MyMessage = [self makeTopButtonWithTitle:@"我的消息" andButtonImageName:@"v2_my_message_icon" buttonType:MyMessageType];
    [self.subviews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
    }];
    
    [MyOrder mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
    }];
    
    [MyCoupon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(MyOrder.mas_right).offset(0);
        make.width.equalTo(MyOrder.mas_width).offset(0);
    }];
    [MyMessage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(MyCoupon.mas_right).offset(0);
        make.width.equalTo(MyCoupon.mas_width).offset(0);
        make.right.offset(0);
    }];
}
- (UIButton *)makeTopButtonWithTitle:(NSString *)title andButtonImageName:(NSString *)imageName buttonType:(MineViewBtnType)type {
    // 1.添加按钮
    UIButton *btn = [[UIButton alloc] init];
    
    // 2.创建图文混排"富文本"属性文本
    NSAttributedString *attStr = [NSAttributedString imageTextWithImage:[UIImage imageNamed:imageName] title:title fontSize:13 titleColor:[UIColor grayColor] spacing:6];
    
    // 3.设置按钮中的属性文字
    [btn setAttributedTitle:attStr forState:UIControlStateNormal];
    // 4.设置按钮中的文字换行
    btn.titleLabel.numberOfLines = 0;
    // 5.设置按钮中的文字居中
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    // 6.添加到父控件上
    [self addSubview:btn];
    // 8.给按钮设置tag
    btn.tag = type;
    [self.arrM addObject:btn];
    return btn;
}


@end
